Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change fractional (and others) to be a property, move quantizers #964

Merged
merged 13 commits into from
Feb 16, 2024

Conversation

jmitrevs
Copy link
Contributor

@jmitrevs jmitrevs commented Feb 8, 2024

Description

This PR has two somewhat unrelated changes. I made the second after the first, so I don't have the second standalone (but can if necessary), and it's easy to extract just the first since it's the first commit. The changes are:

  1. Currently FixedPrecisionType and IntegerPrecisionType have the values width, integer, and fractional set as values stored in the classes. Though they are set properly initially, the values are mutable, so it's possible to edit the values after the fact. It's up to whoever modifies them to make sure they remain consistent. I think that's error-prone. For example, one could modify width in IntegerPrecisionType but leave integer alone, leaving a malformed class. What this PR does is make fractional a property of FixedPrecisonType, always returning width - integer, and a property of IngegerPrecisionType, always returning 0. Similarly integer is a property of IntegerPrecisionType, just returning width. They don't have setters. I also modified the saturation and rounding properties to return the default value if they are set to None, and added similar properties to IntegerPrecisionType but unchangeable, since they are not changeable in the type.
  2. Move quantizers out of types.py into a new quantizers.py file. For qonnx we will add additional quantizers, so my thinking is that it's better to have them in a separate file. But this is not a major issue, so I would be fine reverting it if there are objections.

Type of change

  • Other (Specify)
    Code restructuring

Tests

There should be no changes so the old tests should confirm that I didn't introduce an error.

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

@jmitrevs jmitrevs marked this pull request as draft February 8, 2024 19:44
@jmitrevs jmitrevs marked this pull request as ready for review February 8, 2024 20:42
@vloncar vloncar added the please test Trigger testing by creating local PR branch label Feb 15, 2024
hls4ml/model/types.py Outdated Show resolved Hide resolved
@vloncar vloncar added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Feb 15, 2024
@jmitrevs jmitrevs added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Feb 16, 2024
@jmitrevs
Copy link
Contributor Author

I think this looks good. Since I initially submitted this PR I can't approve it, but if you are happy with it, go ahead and merge it.

@vloncar vloncar merged commit 74647e5 into main Feb 16, 2024
3 of 4 checks passed
@vloncar vloncar deleted the type_properties branch February 16, 2024 01:06
calad0i pushed a commit to calad0i/hls4ml that referenced this pull request Feb 23, 2024
…tmachinelearning#964)

* make fractional a property (plus similar modifications)

* move quantizers to a new quantizers.py from types.py

* remove explicit setting of fractional

* remove setting for fractional that was missed

* Clean up eq function and make everything a property

* Add test for precision type creation

* Nicer docstring for quantizers module

* Move precision parsing test to test_types

* Hardwire saturation bits of int type to 0

* Handle saturation bits for AC types correctly

* Fix return value of __eq__ of PrecisionType base class

---------

Co-authored-by: Vladimir Loncar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants